<template>
	<view>
		<view v-if='sureCheck'>
			<!-- 加工厂 无权查看 显示 暂无数据 -->
			<uni-nodata></uni-nodata>
		</view>
			<view class="orderList" v-else>
					<view class="" style="width: 100%;">
						<u-tabs :list="tabList" is-scroll="false" gutter="75" bar-height="6" bar-width="60" :current="current" @change="changeTab"></u-tabs>
						 
						<u-search placeholder="请输入款号" shape="square" custom='searchList'  margin="25rpx 35rpx" class="searchBox" v-model="searchData.goodsItemNo"></u-search>
						<goods-item :sendList='dataList' :tabState='current'>
						</goods-item>
					</view>
					<uni-nodata v-if="zeroLength"></uni-nodata>
					<!-- <u-empty text=" " v-if="zeroLength" mode="list"></u-empty> -->
					<u-divider  v-if="showBotom">到底了</u-divider>
			</view>
	</view>
</template>

<script>
	import goodsItem from '../workOrder/goodsItem.vue';
	export default {
		components: {
		goodsItem
		},
		data() {
			return {
				sureCheck:true,
				zeroLength:false,
				showBotom:true,
				searchData:{
					pageIndex:0,
					pageSize:10,
					goodsItemNo:'',
					workOrderQueryAndroidStatusEnum:'STATUS_ACCEPT_ORDER'
				},
				dataList:[],
				tabList: [{ name: '待处理' }, { name: '进行中' }, { name: '历史工单' }],
				current: 0,
			}
		},
		onShow() {
			console.log(this.$imgUrl)
			this.dataList=[]
			this.searchData.pageIndex =0
			this.getDataList()
		},
		onReachBottom(){
			console.log('1234567890')
			if(this.showBotom){
				return
			}else{
				this.searchData.pageIndex = Number(this.searchData.pageIndex+1)
				this.getDataList('push')
			}
		},
		onPullDownRefresh() {
		        console.log('refresh');
		        
		    },
		methods: {
			resectList(){
				this.dataList = [];
				this.searchData.pageIndex = 0;
				this.searchData.pageSize = 10;
				this.getDataList();
			},
			clearSearch(){
				console.log('///')
				this.resectList()
			},
			searchList(val){
				console.log(val)
				this.searchData.goodsItemNo = val
				this.resectList()
			},
			getDay(dateTime){
				var EndTime = new Date(dateTime);
				    // 当前系统时间
				    var NowTime = new Date();
				    var t = EndTime.getTime() - NowTime.getTime();
				    var d = Math.floor(t / 1000 / 60 / 60 / 24);
				    var html = d + " 天" ;
				    console.log(html);
					return html
			},
			getDataList(val){
				console.log(val)
				this.$store
					.dispatch('getFactoryWorkOrderList',this.searchData)
					.then(res => {
						if (res.data.errorCode === 0) {
							 console.log(res)
							 let result =res.data.data
							 
							 if(result.content.length>0){
								 result.content.forEach(item=>{
									 item.upDay = this.getDay(item.replyDeliveryDate)
								 })
							 } 
								if(this.searchData.pageIndex >= res.data.data.totalPages ){
									this.showBotom = true
								}else{
									this.zeroLength = false
									 this.showBotom = false
									 this.dataList = this.dataList.concat(res.data.data.content)
								 }
								 if(this.dataList.length == 0){
									 this.zeroLength = true
									 this.showBotom = false
								 }
						}
					})
			},
			getImgUrl(img){
				return 'http://files.ybangy.net/'+img
			},
			changeTab(index) {
				console.log(index)
				this.searchData.goodsItemNo = ''
				this.current = index;
				this.searchData.pageIndex = 0
				this.dataList = []
				switch (index){
					case 0:
					this.searchData.workOrderQueryAndroidStatusEnum = 'STATUS_ACCEPT_ORDER'
					this.getDataList()
					break;
					case 1:
					this.searchData.workOrderQueryAndroidStatusEnum = 'STATUS_MACHINING'
					this.getDataList()
					break;
					case 2:
					this.searchData.workOrderQueryAndroidStatusEnum = 'STATUS_COMPLETED'
					this.getDataList()
					break;
				}
			},
			 
		},
		onLoad() {
			    const value = uni.getStorageSync('userInfo');
			    if (value.userRole == 'sfactory') {
					this.sureCheck = false
			        console.log(value);
					
			    }else{
					this.sureCheck = true
			}
		 }
			
	}
</script>

<style scoped lang="scss">
	.orderList{
background-color: $uni-bg-color;
	min-height: 100vh;
	.cardRow{
		padding:15upx 35upx ; ;
	}
	.cardBox{
		border: 1px solid #C0C0C0;
		border-radius: 10upx;
		box-shadow: 0px 2px 11px 0px rgba(192,192,192,0.5);
		padding:30upx 20upx;
	}
	.leftImg{
		width: 142upx;height: 142upx;
	}
	.statusSpan{
		background:rgba(255,240,239,1);
		border-radius:4px;
		border:1px solid rgba(255,171,166,1);
		color:#FF3B30;
		padding:0 15upx;
	}}
</style>
